@extends('common')
@section('content')
    <form action="{{ url('/execu/entrance')}}" method="post" class="definewidth m20" enctype="multipart/form-data">
        <input type="hidden" name="_token" value="{{ csrf_token() }}" />
        <table style="width:80%;float: left" class="table table-bordered table-hover m10">
            <tr>
                <td class="tableleft">报名时间</td>
                <td><input type="text" id="indate" pattern="^\d{4}-\d{2}-\d{2}$" required value="{{isset($enr_info['enr_time'])?$enr_info['enr_time']:''}}" name="use_enty"></td>
            </tr>
            <tr>
                <td class="tableleft">编号</td>
                <td><input type="text" id="use_num" required="required" pattern="^XY\d{8}$" name="use_num" placeholder="如：XY20160001"/></td>
            </tr>
            <tr>
                <td class="tableleft">姓名</td>
                <td><input type="text" pattern="^[\u4e00-\u9fa5]{2,10}$" required name="use_name" value="{{isset($enr_info['enr_name'])?$enr_info['enr_name']:''}}" placeholder="必须是汉字 如：张三"/></td>
            </tr>
            <tr>
                <td class="tableleft">性别</td>
                <td><select name="use_sex" style="width:150px">
                        <option value="1">男</option>
                        <option value="2">女</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="tableleft">民族</td>
                <td><input type="text" name="use_nation" value="汉" /></td>
            </tr>
            <tr>
                <td class="tableleft">身份证号</td>
                <td><input type="text" id="use_card" pattern="^((\d{15})|(\d{17}[0-9X]))$" required name="use_card" value="{{isset($enr_info['enr_card'])?$enr_info['enr_card']:''}}" placeholder="输入正确格式的身份证"/></td>
            </tr>
            <tr>
                <td class="tableleft">户口所在地</td>
                <td>
                    <select name="origin_pro" id="province" style="width:120px">
                        @foreach($province as $v)
                            <option value="{{$v['region_id']}}">{{$v['region_name']}}</option>
                        @endforeach

                    </select>
                    <select name="origin_city" style="width:120px" id="city">
                        <option value="2">北京</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="tableleft">现居住地</td>
                <td>
                    <select name="address_pro" id="province1" style="width:120px">
                        @foreach($province as $v)
                            <option value="{{$v['region_id']}}">{{$v['region_name']}}</option>
                        @endforeach

                    </select>
                    <select name="address_city" style="width:120px" id="city1" onchange="s_district1()">
                        <option value="2">北京</option>
                    </select>
                    <select name="address_dis" style="width:120px" id="district1">
                        <option value="502">海淀区</option>
                    </select><br />
                    <textarea name="address_info" cols="50" rows="3" placeholder="详细地址"></textarea>
                </td>
            </tr>
            <tr>
                <td class="tableleft">联系电话</td>
                <td><input type="text" pattern="^1[3-9]\d{9}$" required name="use_phone" value="{{isset($enr_info['enr_phone'])?$enr_info['enr_phone']:''}}" placeholder="手机格式 如：13872951238"/></td>
            </tr>
            <tr>
                <td class="tableleft">邮箱</td>
                <td>
                    <input type="text" pattern="^\w+@\w+(\.)com|net|cn|edu$" required name="use_email" placeholder="如：zhangsan@sina.com"/>
                </td>
            </tr>
            <tr>
                <td class="tableleft">报名课程</td>
                <td>
                    <select name="cou_id">
                        @foreach($cou_name as $v)
                            <option value="{{$v['cou_id']}}">{{$v['cou_name']}}</option>
                        @endforeach
                    </select>
                </td>
            </tr>
            <tr>
                <td class="tableleft">报名类型</td>
                <td><select name="per_id" style="width:120px">
                        @foreach($pap as $v)
                            <option value="{{$v['pap_id']}}">{{$v['pap_name']}}</option>
                        @endforeach
                    </select></td>
            </tr>
            <tr>
                <td class="tableleft">体检结果</td>
                <td><select name="stu_medical" style="width:120px">
                        <option value="未体检">
                            未体检
                        </option>
                        <option value="体检合格">
                            体检合格
                        </option>
                        <option value="体检未合格">
                            体检未合格
                        </option>
                    </select></td>
            </tr>
            <tr>
                <td class="tableleft"></td>
                <td>
                    <button type="submit" id="sub" class="btn btn-primary">保存</button> &nbsp;&nbsp;<button type="reset" class="btn btn-success" name="backid" id="backid">重置</button>
                </td>
            </tr>
        </table>
        <div style="margin-left:20px;float:left;width:200px;height:200px;border:1px solid gray"><div id="lodimg" style="display:none;float: left;margin-right: 10px;" >
                <img id="lodingpic">
            </div>
            <input id="loding" onchange="javascript:setImagePreview();" type="file" name="use_pic" accept="image/png,image/gif,image/jpg" required></div>
    </form>
    <script src="{{url('assets/js/loadingpic.js')}}"></script>
    <script src="{{url('api/jedate/jedate.js')}}"></script>
    <script type="text/javascript">
        jeDate({
            dateCell:"#indate",
            format:"YYYY-MM-DD",
            isinitVal:true,
            isTime:true, //isClear:false,
            minDate:"2000-01-01",
            okfun:function(val){alert(val)}
        })
            $('#province').on('change',function ()
            {
                var p_id=$('#province').val();
                var url="{{ url('execu/s_area')}}";
                //alert(p_id);
                $.get(url, { p_id: p_id},
                        function(msg){
                            //alert("Data Loaded: " + msg);
                            if(msg==0)
                            {
                                document.getElementById('city').length=0;
                                $("#city").html("<option>无</option>");                                  document.getElementById('district').length=0;
                                $("#district").html("<option>无</option>");
                            }
                            else
                            {

                                document.getElementById('city').length=0;
                                var arr=eval('('+msg+')');
                                //alert(arr);
                                //alert(typeof (arr));
                                for(i=0;i<arr.length;i++)
                                {
                                    var id=arr[i]['region_id'];
                                    var name=arr[i]['region_name'];
                                    op=new Option(name,id);
                                    document.getElementById('city').options.add(op);
                                }
                            }
                        });
            });
        $('#province1').on('change',function ()
        {
            var p_id=$('#province1').val();
            var url="{{ url('execu/s_area')}}";
            //alert(p_id);
            $.get(url, { p_id: p_id},
                    function(msg){
                        //alert("Data Loaded: " + msg);
                        if(msg==0)
                        {
                            document.getElementById('city1').length=0;
                            $("#city1").html("<option>无</option>");                                  document.getElementById('district1').length=0;
                            $("#district1").html("<option>无</option>");
                        }
                        else
                        {

                            document.getElementById('city1').length=0;
                            var arr=eval('('+msg+')');
                            //alert(arr);
                            //alert(typeof (arr));
                            for(i=0;i<arr.length;i++)
                            {
                                var id=arr[i]['region_id'];
                                var name=arr[i]['region_name'];
                                op=new Option(name,id);
                                document.getElementById('city1').options.add(op);
                            }
                            s_district1();
                        }
                    });
        });
        function s_district1() {
            var p_id = $('#city1').val();
            var url="{{ url('execu/s_area')}}";
            $.get(url, { p_id: p_id},
                    function(msg){
                        if(msg==0)
                        {
                            document.getElementById('district1').length=0;
                            $("#district1").html("<option>无</option>");
                        }
                        else
                        {
                            document.getElementById('district1').length = 0;
                            var arr = eval('(' + msg + ')');
                            //alert(typeof (arr));
                            for (i = 0; i < arr.length; i++) {
                                var id = arr[i]['region_id'];
                                var name = arr[i]['region_name'];
                                op = new Option(name, id);
                                $('#district1')[0].options.add(op);
                            }
                        }
                    });
        };

        $("#use_num").blur(function(){
            var num=$(this).val();
            var url="{{ url('execu/checkNum') }}";
            $.get(url, { num: num},
               function(data){
                        if(data==1)
                        {
                            alert("编号已存在");
                            $("#sub").attr('disabled','true');                                       }
                        else if(data==2)
                        {
                            $("#sub").removeAttr('disabled');
                        }
            });
        })
        $("#use_card").blur(function(){
            var card=$(this).val();
            var url="{{ url('execu/checkCard') }}";
            $.get(url, { card: card},
                    function(data){
                        if(data==1)
                        {
                            alert("该用户已存在，请填写正确的身份证号");
                            $("#sub").attr('disabled','true');                                       }
                        else if(data==2)
                        {
                            $("#sub").removeAttr('disabled');
                        }
                    });
        })
    </script>
@stop